// SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC.
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "argmax_device_operation_types.hpp"
#include "argmax_multi_core_program_factory.hpp"
#include "argmax_single_core_program_factory.hpp"
#include "ttnn/decorators.hpp"
#include "ttnn/tensor/tensor.hpp"

#include <optional>

namespace ttnn::operations::reduction::argmax {

struct ArgMaxDeviceOperation {
    using operation_attributes_t = argmax::operation_attributes_t;
    using tensor_args_t = argmax::tensor_args_t;
    using spec_return_value_t = argmax::spec_return_value_t;
    using tensor_return_value_t = argmax::tensor_return_value_t;
    using program_factory_t =
        std::variant<program::ArgMaxSingleCoreProgramFactory, program::ArgMaxMultiCoreProgramFactory>;

    static program_factory_t select_program_factory(const operation_attributes_t&, const tensor_args_t&);

    static void validate_on_program_cache_hit(const operation_attributes_t&, const tensor_args_t&);
    static void validate_on_program_cache_miss(const operation_attributes_t&, const tensor_args_t&);

    static spec_return_value_t compute_output_specs(const operation_attributes_t&, const tensor_args_t&);

    static tensor_return_value_t create_output_tensors(
        const operation_attributes_t& operation_attributes, const tensor_args_t&);

    static std::tuple<operation_attributes_t, tensor_args_t> invoke(
        const Tensor& input,
        tt::tt_metal::DataType output_dtype,
        std::optional<int> dim,
        bool keepdim,
        const std::optional<CoreRangeSet>& sub_core_grids,
        bool use_multicore,
        const tt::tt_metal::MemoryConfig& output_mem_config,
        std::optional<Tensor> optional_output_tensor);
};

}  // namespace ttnn::operations::reduction::argmax

namespace ttnn::prim {
constexpr auto argmax =
    ttnn::register_operation<"ttnn::prim::argmax", ttnn::operations::reduction::argmax::ArgMaxDeviceOperation>();
}  // namespace ttnn::prim
